package com.njegovanobradovic.components;

import java.util.List;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.njegovanobradovic.entities.Page;
import com.njegovanobradovic.pages.Index;
import com.njegovanobradovic.so.Get;
import com.njegovanobradovic.so.GetAll;
import com.njegovanobradovic.so.GetHomePage;

public class Header {
	@Inject
	private GetAll<Page> getAllPages;
	@Inject
	private Get<Page> getPage;
	@Property
	private Page page;
	@InjectPage
	private Index index;
	
	public List<Page> getPages(){
		getAllPages.setSearchForType(Page.class);
		return getAllPages.execute();
	}
	
	public Object onShowPage(Long id) {
		try {
			getPage.setId(id);
			getPage.setSearchForType(Page.class);
			index.setPage(getPage.execute());
			return index;
		} catch (Exception e) {
			return null;
		}
	}
	
	
	@Inject
	private GetHomePage getHomePage;
	public Object onShowHomePage(){
		try {
			index.setPage(getHomePage.execute());
			return index;
		} catch (Exception e) {
			return null;
		}
	}
}
